package com.operator.Activitys.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.operator.Activitys.R;
import com.operator.Activitys.activity.base.BaseActivity;
import com.operator.Activitys.bean.CardOrder;
import com.operator.Activitys.bean.User;
import com.operator.Activitys.utils.Constant;

import butterknife.Bind;

/**
 * 项目名称：金泽云 手机app
 * 类描述：号卡订单详情
 * 创建人：张飞祥
 * 创建时间：2018/5/22 10:25
 * 修改人：张飞祥
 * 修改时间：2018/5/22 10:25
 * 修改备注：
 */
public class CardDetailsActivity extends BaseActivity {

    //返回按钮
    @Bind(R.id.iv_return)
    ImageView ivReturn;
    //标题
    @Bind(R.id.tv_title)
    TextView tvTitle;
    //订单号
    @Bind(R.id.tv_details_order_number)
    TextView tvDetailsOrderNumber;
    //下单时间
    @Bind(R.id.tv_details_order_time)
    TextView tvDetailsOrderTime;
    //客户名称
    @Bind(R.id.tv_details_user_name)
    TextView tvDetailsUserName;
    //卡号
    @Bind(R.id.tv_details_card_number)
    TextView tvDetailsCardNumber;
    //订单结果
    @Bind(R.id.tv_details_state_result)
    TextView tvDetailsStateResult;
    //身份证号
    @Bind(R.id.tv_details_id_number)
    TextView tvDetailsIdNumber;
    //号卡类别
    @Bind(R.id.tv_details_type)
    TextView tvDetailsType;
    //号卡套餐
    @Bind(R.id.tv_details_set_meal)
    TextView tvDetailsSetMeal;
    //业务员姓名
    @Bind(R.id.tv_details_work_name)
    TextView tvDetailsWorkName;
    //业务员电话
    @Bind(R.id.tv_details_work_phone)
    TextView tvDetailsWorkPhone;
    //业务员电话
    @Bind(R.id.tv_details_refund_reason)
    TextView tvDetailsRefundReason;
    //备注
    @Bind(R.id.tv_details_remark)
    TextView tvDetailsRemark;
    //iccid
    @Bind(R.id.tv_details_iccid)
    TextView tvDetailsIccid;


    //接收者
    private CardOrder order = null;
    //内存中用户实体
    protected User mACacheUser = null;

    @Override
    protected void initUI() {
        setContentView(R.layout.act_card_details);
        //设置状态栏为透明
        setThemeTransparent();
        //设置标题
        tvTitle.setText("订单详情");
        //显示返回按钮
        ivReturn.setVisibility(View.VISIBLE);
        //返回按钮事件
        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void initData() {
        //获取内存用户实体
        mACacheUser = new Gson().fromJson(mACache.getAsJSONObject(Constant.CACHE_USER) + "", User.class);
        /**
         * 获取数据源
         */
        Bundle bundle = this.getIntent().getExtras();
        if (bundle != null) {
            //TODO 获取 传递过来的实体数据
            order = (CardOrder) bundle.getSerializable(Constant.INTENT_ORDER_CARD_BEAN);
            //TODO 填充实体数据到页面上
            setOrderData();
        }
    }

    /**
     * 填充数据
     */
    private void setOrderData() {
        //订单号
        tvDetailsOrderNumber.setText(order.getOrderId() + "");
        //下单时间
        tvDetailsOrderTime.setText(order.getCreateTime());
        //客户名称
        if (order.getCustomerName() != null && !"".equals(order.getCustomerName()))
            tvDetailsUserName.setText(order.getCustomerName());
        else
            tvDetailsUserName.setText("无客户姓名（" + order.getCarrieroperator() + "）");
        //手机号
        tvDetailsCardNumber.setText(order.getTelNumber());

        //订单结果
        tvDetailsStateResult.setText(order.getResState());

        //身份证号
        if (order.getIDCardNum() != null && !"".equals(order.getIDCardNum()))
            tvDetailsIdNumber.setText(order.getIDCardNum());
        else
            tvDetailsIdNumber.setText("无");

        //iccid
        if (order.getICCID() != null && !"".equals(order.getICCID()))
            tvDetailsIccid.setText(order.getICCID());
        else
            tvDetailsIccid.setText("无");

        //号卡类别（电信、移动、联通）
        tvDetailsType.setText(order.getCarrieroperator());

        //号卡套餐
        tvDetailsSetMeal.setText(order.getTelephoneSetTitle());

        //业务员姓名
        if (!mACacheUser.getCountermanName().equals(""))
            tvDetailsWorkName.setText(mACacheUser.getCountermanName());
        else
            tvDetailsWorkName.setText("暂无业务员姓名");

        //业务员电话
        if (!mACacheUser.getCountermanTel().equals(""))
            tvDetailsWorkPhone.setText(mACacheUser.getCountermanTel());
        else
            tvDetailsWorkPhone.setText("暂无业务员电话");

        //退款原因
        if (order.getReasonsForRefunds() != null && !"".equals(order.getReasonsForRefunds()))
            tvDetailsRefundReason.setText(order.getReasonsForRefunds());
        else
            tvDetailsRefundReason.setText("无");

        //备注
        if (order.getRemark() != null && !"".equals(order.getRemark()))
            tvDetailsRemark.setText(order.getRemark());
        else
            tvDetailsRemark.setText("无");
    }
}
